function generateOption () {
	var categoryArr = ['吸尘器', '微波炉', '洗碗机'];
	var month = '5月';
	var brand = '美的';
	var option = [];
	var startOption = [
		{ name: '封面', color: 'color1', array: null },
		{ name: '数据说明', color: 'color2', array: null },
		{ name: '目录', color: 'color3', array: null },
		{ name: month + '厨热行业概览', color: 'color4', array: null },
		{ name: brand + '厨热各品类概览', color: 'color4', array: null },
		{ name: '厨热行业销额趋势', color: 'color4', array: null },
		{ name: brand + '店铺口碑表现', color: 'color4', array: null },
	];

	var categoryOption = [];
	categoryArr.forEach(function (category) {
		// 目录
		categoryOption.push({ name: '目录--' + category, color: 'color3', array: null });
		// 品类行业概览
		categoryOption.push({ name: category + '行业概览', color: 'color4', array: null });
		// 品类销额趋势
		categoryOption.push({ name: category + '销额趋势' + category, color: 'color4', array: null });
		// 分价格段品牌表现
		categoryOption.push({ name: '分价格段品牌表现' + category, color: 'color4', array: generateSegOption(category) });
	});

	var endOption = [
		{ name: brand + '痛点分析', color: 'color4', array: null },
		{ name: brand + '产品口碑分析', color: 'color4', array: null },
		{ name: '封底', color: 'color1', array: null }
	];

	option = option.concat(startOption, categoryOption, endOption);
	return option;
}

function generateSegOption (category) {
	var array = [];
	if (category === '吸尘器') {
		array = [
			{ name: '1000元以下'},
			{ name: '1000~1500'},
			{ name: '1500~2000'},
			{ name: '2000~2500'},
		]
	} else if (category === '微波炉') {
		array = [
			{ name: '1000~1500'},
			{ name: '1500~2000'},
			{ name: '2000~2500'},
		]
	} else if (category === '洗碗机') {
		array = [
			{ name: '2000元以下'},
			{ name: '2000~2500'}
		]
	}
	array.forEach(function(item) {
		item.category = category;
		item.color = 'color5';
	});
	return array;
}

function init () {
	var $container = $('.list');
	var str = '';
	var option = generateOption();
	option.forEach(function (item) {
		str += '<li class="item flex justify-content-center align-items-center '+ item.color +'">'+ item.name +'</li>';
		if (item.array && item.array.length) {
			var array = item.array;
			array.forEach(function (jItem) {
				str += '<li class="item flex justify-content-center align-items-center '+ jItem.color +'">'+ jItem.name +'</li>';
			});
		}
	});
	$container.append(str);
}

var list0 = [
	{ name: 'tom', age: 24 },
	{ name: 'cat', age: 18 },
	{ name: 'fish', age: 22 },
	{ name: 'zero', age: 25 }
]

var list1 = [
	{ name: 'jim', sex: 'male' },
	{ name: 'jason', sex: 'male' },
	{ name: 'sally', sex: 'male' },	
]

function test () {
	var startList = [
		{ flag: 'start' }
	];
	var categoryArr = ['a', 'b'];
	var categoryList = [];
	var idx = 0;
	categoryArr.forEach(async function (item, index) {
		var result = await fetchList(index);
		categoryList = categoryList.concat(result);
		idx++;
		console.log(idx, categoryList)
		// fetchList(index)
		// 	.then(function(result) {
		// 		categoryList = categoryList.concat(result)
		// 	})
	});
	var interval = setInterval(function () {
		if (idx === categoryArr.length) {
			var endList = [
				{ flag: 'end' }
			];
			var result = [];
			result = result.concat(startList, categoryList, endList);
			console.log(result)
			clearInterval(interval)
		}
	}, 10000)
}

function fetchList (index) {
	return new Promise(function (resolve, reject) {
		setTimeout(function () {
			var list = window['list'+ index];
			resolve(list)
		}, 100)
	});
}

$(function () {
	init();
	test();
})